home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / ANTENNA / YAGIU112 / MUTUAL.C < prev    next >
C/C++ Source or Header  |  1995-08-20  |  3KB  |  111 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <errno.h>
  4. #include "yagi.h"
  5.  
  6. extern int errno;
  7.  
  8. void mutual_impedance(int i, int j, double frequency, int driven, int parasitic, double **d, double **p, double **impedance)
  9. {
  10.     double xi, yi, xj, yj, li, lj, s, lamda, real, imag, mean_length;
  11.     int col;
  12.     /* first find location x,y of first element */
  13.     if(i<=driven)                /* i is a  driven element*/
  14.     {
  15.         xi=d[i][X];
  16.         yi=d[i][Y];
  17.         li=d[i][LENGTH];
  18.     }
  19.     else if (i>driven)            /* i is a  parasitic  element */
  20.     {
  21.         xi=p[i-driven][X];
  22.         yi=p[i-driven][Y];
  23.         li=p[i-driven][LENGTH];
  24.     }
  25.     if(j<=driven)                /* j is a  driven element*/
  26.     {
  27.         xj=d[j][X];
  28.         yj=d[j][Y];
  29.         lj=d[j][LENGTH];
  30.     }
  31.     else if (j>driven)            /* i is a  parasitic  element */
  32.     {
  33.         col=j-driven;
  34.         xj=p[col][X]; 
  35.         yj=p[col][Y];
  36.         lj=p[col][LENGTH];
  37.     }
  38.     /* compute distance from element i to element j */
  39.     s=sqrt((xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)); /* in metres */
  40.     mean_length=(li+lj)/2.0;
  41.     lamda=3e8/frequency; 
  42.     z21(lamda, s , mean_length , &real, &imag);
  43.     /* fill in Zij and Zji at the same time, as matrix is symmetric. */
  44.     impedance[i][(2*j)-1]=real; /* real; */
  45.     impedance[i][2*j]=imag; /* imag; */
  46.     impedance[j][2*i-1]=real; /* real; */
  47.     impedance[j][2*i]=imag; /* imag; */
  48.  
  49. #ifdef DEBUG
  50.     if(errno)
  51.     {
  52.         fprintf(stderr,"Errno =%d in  mutual.c\n", errno);
  53.         exit(1);
  54.     }
  55. #endif
  56. }
  57.  
  58. /* To find the mutual impedance between to arbitary length, thin elements
  59. I used the equations on Krauss, Antennas, McGraw Hill, 1988, pp426 and
  60. 427. Original work from Brown and King, 'High Frequency Models in Antenna
  61. Investigations', Proc IRE, vol 22, pp457-480, April 1934*/
  62. void z21(double lamda, double d, double l, double *r21, double *x21)
  63. {
  64.  
  65.     double  b, cos_bl, sin_bl, sin_bl_over_2, cos_bl_over_2, c, s ;
  66.     double t1, t2, t3, t4;
  67.     double si_t1, ci_t1, si_t4, ci_t4, ci_bd, si_bd;
  68.     double ci_t2, si_t2, ci_t3, si_t3;
  69.  
  70.     b=M_PI*2/lamda;
  71.     t1=b*(sqrt(d*d+l*l)+l);
  72.     t2=0.5*b*(sqrt(4*d*d+l*l)-l);
  73.     t3=0.5*b*(sqrt(4*d*d+l*l)+l);
  74.     t4=b*(sqrt(d*d+l*l)-l);
  75.     /* To save findinding the same slow trigometric and ever slower
  76.     si and ci functions, I'll just look them up once */
  77.     cos_bl=cos(b*l);
  78.     sin_bl=sin(b*l);
  79.     sin_bl_over_2=sin(b*l/2);
  80.     cos_bl_over_2=cos(b*l/2);
  81.     s=sin_bl_over_2*sin_bl_over_2;
  82.     c=cos_bl_over_2*cos_bl_over_2;
  83.  
  84.     cisi(t1, &ci_t1, &si_t1);
  85.     cisi(t2,&ci_t2, &si_t2);
  86.     cisi(t3,&ci_t3, &si_t3);
  87.     cisi(t4, &ci_t4, &si_t4);
  88.     cisi(b*d,&ci_bd, &si_bd);
  89.     /* Real part of mutual impedance, computed as equation on page
  90.     426 of Kraus */
  91.     *r21=(30/s)*(2*(2+cos_bl)*ci_bd
  92.     -4*c*( ci_t2 + ci_t3 )
  93.     +cos_bl*( ci_t4 + ci_t1 )
  94.     +sin_bl* ( si_t1 - si_t4 -2*si_t3 +2*si_t2 ) );
  95.  
  96.     /* Imaginary part of mutual impedance, computed as equation on page
  97.     427 of Kraus */
  98.     *x21=(30/s)*(-2*(2+cos_bl)*si_bd
  99.     +4*c*( si_t2 + si_t3 )
  100.     -cos_bl*( si_t4 + si_t1 )
  101.     +sin_bl* ( ci_t1 - ci_t4 -2*ci_t3 +2*ci_t2 ) );
  102. #ifdef DEBUG
  103.     if(errno)
  104.     {
  105.         fprintf(stderr,"Errno =%d in  z21() mutual.c\n", errno);
  106.         exit(1);
  107.     }
  108. #endif
  109. }  
  110.  
  111.